package com.epam.facebook_client.processor;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import com.epam.facebook_client.content.contract.AppContract;
import com.epam.facebook_client.manager.HttpClientManager;
import com.epam.facebook_client.parser.FbJsonParser;

public class AlbumsProcessor extends AbstractProcessor {

	//private static final String TAG = AlbumsProcessor.class.getSimpleName();
	public static final String ACTION = "action_album";
	public static final String EXTRA_NAME = "extra_album_name";
	public static final String EXTRA_RESPONSE = "extra_response";
	
	public AlbumsProcessor(Context context) {
		super(context);
	}
	
	@Override
	public Bundle executeGet(Intent intent) throws Exception {
		String url = intent.getStringExtra(EXTRA_URL);
		
		writeInDB(url, new FbJsonParser(getContext()));
		
		return null;
	}

	@Override
	public Bundle executeDelete(Intent intent) throws Exception {
		getContext().getContentResolver().delete(getUri(), null, null);
		return executeGet(intent);
	}

	@Override
	public Bundle executePost(Intent intent) throws Exception {
		String name = intent.getExtras().getString(EXTRA_NAME);
		String url = intent.getExtras().getString(EXTRA_URL);
		Map<String, String> params = new HashMap<String, String>(1);
		params.put(HttpClientManager.POST_NAME, name);
		String response = HttpClientManager.get(getContext()).postString(url, params);
		Bundle bundle = new Bundle();
		bundle.putString(EXTRA_RESPONSE, response);
		return bundle;
	}

	@Override
	protected Uri getUri() {
		return AppContract.AlbumColumns.CONTENT_URI;
	}

}
